<template>
	<view class="academicBox">
		<view class="tabsBox">
			<view class="tabtype" @click="handleType(0)">
				<view class="text" :class="currIndex==0 ? 'texted' :''">
					校内成绩
				</view>
				<view v-if="currIndex==0" class="heng"></view>
			</view>
			<view class="tabtype" @click="handleType(1)">
				<view class="text" :class="currIndex==1 ? 'texted' :''">
					标化考试
				</view>
				<view v-if="currIndex==1" class="heng"></view>
			</view>
		</view>

		<view v-if="currIndex==0" class="">
			<view v-if="XnList.length" class="listBox">
				<view class="listitem" v-for="(item,index) in XnList">
					<view class="topBox">
						<image src="../../static/image/iconfool.png" style="width: 48rpx;height: 48rpx;" mode="">
						</image>
						<view class="" style="margin-left: 20rpx;">
							<text>{{item.age}}</text>
							<text style="margin-left: 30rpx;">{{item.semester}}</text>
						</view>
					</view>
					<view class="content">
						<view class="contenttop">
							<view class="lable" style="width: 50%;text-align: center;">
								考试学科
							</view>
							<view class="lable" style="width: 50%;text-align: center;">
								考试成绩
							</view>

						</view>

						<view class="contentBottom" v-for="(subitem,subindex) in item.achievement">
							<view class="value" style="width: 50%;text-align: center;">
								{{subitem.discipline}}
							</view>
							<view class="value" style="width: 50%;text-align: center;">
								{{subitem.achievement}}
							</view>

						</view>
						<view class="heng"></view>
						<view class="footerBox">
							<view class="">
								{{item.remark==null?'':item.remark}}
							</view>
							<view class="" style="margin-top: 20rpx;display: flex;flex-wrap: wrap;">
								<image class="itemimg" v-for="(douitem,douindex) in item.remark_image" :src="douitem"
									style="width: 150rpx;height: 150rpx;border-radius: 10rpx;margin-right: 20rpx;margin-bottom: 10rpx;"
									mode="" @click="handleimgbig(item.remark_image)"></image>
							</view>
						</view>
					</view>



				</view>

			</view>


			<view v-else class="" style="width:148rpx ;text-align: center;margin: 0 auto;margin-top: 100rpx;">
				<image src="../../static/image/nullimg.png" style="width: 148rpx;height: 148rpx;" mode=""></image>
				<view class="" style="color: #AEB8C2;">
					暂无成绩
				</view>
			</view>


		</view>

		<view v-if="currIndex==1" class="">
			<view v-if="BhList.length" class="listBox">
				<view class="listitem" v-for="(item,index) in BhList" @click="handleBhdetail(item)">
					<view class="topBox">
						<image src="../../static/image/iconfool.png" style="width: 48rpx;height: 48rpx;" mode="">
						</image>
						<view class="" style="margin-left: 20rpx;">
							考试类型:{{item.type_text == 'Others' ? 'Others' : item.type_text}}
						</view>
						<!-- <view class="" style="margin-left: 20rpx;">
							考试{{index +1}}
						</view> -->

					</view>
					
					<view v-if="item.type_text != 'Others'" class="content">
						<view class="contenttop">
							<view class="lable" style="width: 50%;">
								考试时间
							</view>
							<view class="lable" style="width: 50%;">
								考试成绩
							</view>
						</view>

						<view class="contentBottom" v-for="(subitem,subindex) in item.children">
							<view class="value" style="width: 50%;">
								{{subitem.created_at}}
							</view>

							<view v-if="item.type == 1 || item.type == 2 || item.type == 3" class="value"
								style="width: 50%;">
								{{subitem.achievement_zong !=null ? subitem.achievement_zong :""}}
							</view>
							<view v-if="item.type == 4" class="value" style="width: 50%;">
								{{subitem.sta_achievement_zong !=null ? subitem.sta_achievement_zong :""}}
							</view>
							<view v-if="item.type == 5" class="value" style="width: 50%;">
								{{subitem.act_achievement_zong !=null ? subitem.act_achievement_zong :""}}
							</view>
							<view v-if="item.type ==6" class="value" style="width: 50%;">
								{{subitem.gre_achievement_zong !=null ? subitem.gre_achievement_zong :""}}
							</view>
							<view v-if="item.type ==7" class="value" style="width: 50%;">
								{{subitem.gmat_achievement_zong !=null ? subitem.gmat_achievement_zong :""}}
							</view>
							<view v-if="item.type_text == 'Others'" class="value" style="width: 50%;">
								{{subitem.other_achievement_zong !=null ? subitem.other_achievement_zong :""}}
							</view>

						</view>
					</view>
					
					<view v-else class="content">
						
						<view class="contenttop">
							<view class="lable" style="width: 33.33%;">
								考试科目
							</view>
							<view class="lable" style="width: 33.33%;">
								考试时间
							</view>
							<view class="lable" style="width: 33.33%%;">
								考试成绩
							</view>
						</view>
						
						<view class="contentBottom" v-for="(subitem,subindex) in item.children">
							<view class="value" style="width: 33.33%;">
								{{subitem.other_type}}
							</view>
							
							<view class="value" style="width: 33.33%;">
								{{subitem.created_at}}
							</view>
					
							<view class="value" style="width: 33.33%;">
								{{subitem.other_achievement_zong !=null ? subitem.other_achievement_zong :""}}
							</view>
						
						</view>
						
						
					</view>
					
					
					
					
					<view class="heng"></view>
					<view class="footerBox" style="display: flex;align-items: center;">
						<view class="">
							查看详情
						</view>
						<u-icon name="arrow-right-double" color="#CCCCCC" size="20"></u-icon>
					</view>
				</view>

			</view>

			<view v-else class="" style="width:148rpx ;text-align: center;margin: 0 auto;margin-top: 100rpx;">
				<image src="../../static/image/nullimg.png" style="width: 148rpx;height: 148rpx;" mode=""></image>
				<view class="" style="color: #AEB8C2;">
					暂无成绩
				</view>
			</view>
		</view>

		<view class="" style="height: 100rpx;"></view>

	</view>
</template>

<script>
	import {
		userAcademic
	} from "@/api/api.js"
	export default {
		data() {
			return {
				currIndex: 0,
				pageId: "",
				XnList: [],
				BhList: [],
				pageData: {},
			}
		},
		onLoad(options) {
			this.pageId = options.id
		},
		onShow() {
			this.handleuserAcademic()
		},
		onPullDownRefresh() {
			// console.log("触发了下拉刷新"),
			this.handleuserAcademic()
			uni.stopPullDownRefresh();
		},
		methods: {

			async handleuserAcademic() {
				let res = await userAcademic({
					page: 1,
					page_size: 10,
					type: this.currIndex + 1,
					id: this.pageId,
				})
				if (this.currIndex == 0) {
					this.XnList = res.data

					this.XnList.forEach((item, index) => {
						console.log("item.achievement?????",item.achievement)
						item.achievement = JSON.parse(item.achievement)
						if (item.remark_image) {
							item.remark_image = item.remark_image.split(",")
						}
					})
				} else {
					this.BhList = res.data
					// this.BhList.forEach((item, index) => {
					// 	item.sum = item.achievement * 1 + item.achievement1 * 1 + item
					// 		.achievement2 * 1 + item.achievement3 * 1
					// })

				}

				this.pageData = res.data.data[0]
				this.pageData.remark_image = this.pageData.remark_image == null || this.pageData.remark_image == "" ?
				[] : this.pageData.remark_image.split(",")

			},
			handleType(index) {
				this.currIndex = index
				this.handleuserAcademic()
			},
			handleimgbig(imgarr) {
				uni.previewImage({
					current: 0, // 当前显示图片的链接（必填）
					urls: imgarr, // 要预览的图片链接列表（必填）
					success() {
						// console.log('预览图片成功');
					},
					fail(err) {
						// console.log('预览图片失败', err);
					}
				});
			},
			handleBhdetail(item) {
				console.log("item", item)
				uni.navigateTo({
					url: `./examresult?id=${item.id}`
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.academicBox {
		.tabsBox {
			width: 100%;
			height: 100rpx;
			background-color: #ffffff;
			display: flex;
			padding-top: 30rpx;
			box-sizing: border-box;

			.tabtype {
				width: 50%;
				font-size: 30rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				line-height: 34rpx;
				text-align: center;
				display: flex;
				flex-direction: column;
				align-items: center;

				.heng {
					width: 52rpx;
					height: 8rpx;
					background: #255A9B;
					border-radius: 200rpx 200rpx 200rpx 200rpx;
					margin-top: 30rpx;
				}

				.texted {
					color: #255A9B;
				}
			}
		}

		.listBox {
			width: 690rpx;
			margin: 0 auto;
			margin-top: 30rpx;

			.listitem {
				width: 690rpx;
				// height: 354rpx;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin-bottom: 30rpx;

				.topBox {
					width: 690rpx;
					height: 92rpx;
					background: #E1E8FD;
					border-radius: 16rpx 16rpx 0 0;
					padding: 22rpx 20rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #255A9B;
					line-height: 32rpx;
				}

				.content {
					padding: 30rpx;
					box-sizing: border-box;

					.contenttop {
						display: flex;
						text-align: center;

						.lable {
							width: 33.33%;
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #232832;
							line-height: 36rpx;
						}

					}

					.contentBottom {
						display: flex;
						margin-top: 30rpx;

						.value {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #9E9E9E;
							line-height: 36rpx;
							width: 33.33%;
							text-align: center;
						}
					}
				}

				.heng {
					width: 650rpx;
					height: 1rpx;
					background-color: #F4F4F7;
					margin: 0 auto;
					margin-top: 20rpx;
				}

				.footerBox {
					padding: 30rpx 60rpx;
					box-sizing: border-box;
					// display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					// color: #CCCCCC;
					line-height: 28rpx;

					.itemimg:nth-child(3n) {
						margin-right: 0rpx;
					}
				}

			}
		}
	}
</style>